const path=require('path');
const fs=require('fs');
const {Article}=require('../../model/article');

module.exports=async(req,res)=>{
    const id=req.query.id;
    let result=await Article.findById(id);
    const img_path=path.join(__dirname,'../../public',result.cover);
    // 删除图片
    fs.unlink(img_path,(err,result)=>{
        if(err) return console.log(err);
    })
    await Article.findByIdAndDelete(req.query.id);
    res.redirect('/admin/article');
}